#ifndef _DATABASE_H_
#define _DATABASE_H_

#include "rlock.h"
#include "rdb.h"

const string gs_database_name = "holddo-9001";
const string gs_database_host = "localhost";

class database
{
	private:
		database();
		~database();

		database(const database&);
		database& operator=(const database&);

		string get_login_string( const string &s_db_name, const string &s_ip = gs_database_host );
		bool db_connect( const string &s_db_name, const string &s_ip  ) ; 
		static void *routine_keepalive(void* arg);
		void entry_keepalive( void* arg ) ;
		bool background_routines( void ) ; 

		pthread_mutex_t m_lock;
		otl_connect m_db;
		string ms_login ;

	public:
		static database& _instance()
		{
			static database instance ;
			return instance ;
		}
		
		bool init( const string &s_db_name = gs_database_name, const string &s_ip = gs_database_host );

		bool get_daemon_version( const string& s_sub_vender, string& s_version, string& s_path ) ;
		bool get_control_version( const string& s_sub_vender, string& s_version, string& s_path ) ;
		bool get_display_version( const string& s_sub_vender, string& s_version, string& s_path ) ;
};

#endif
